// window.onerror异常捕获
window.onerror = function (message, source, lineno, colno, error) {
    console.log('捕获到异常：', { message, source, lineno, colno, error });
};

// 静态资源异常捕获
window.addEventListener('error', (error) => {
    console.log('捕获到异常：', error);
}, true);

// Promise 异常捕获
window.addEventListener("unhandledrejection", function (e) {
    console.log('捕获到异常：', e);
});

// 监控网页崩溃和卡顿
window.addEventListener('load', function () {
    sessionStorage.setItem('good_exit', 'pending');
    setInterval(function () {
        sessionStorage.setItem('time_before_crash', new Date().toString());
    }, 1000);
});

window.addEventListener('beforeunload', function () {
    sessionStorage.setItem('good_exit', 'true');
});

if (sessionStorage.getItem('good_exit') && sessionStorage.getItem('good_exit') !== 'true') {
    alert('Hey, welcome back from your crash, looks like you crashed on: ' + sessionStorage.getItem('time_before_crash'));
}